package eg.com.itiga.repositoryimpl.company;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import eg.com.itiga.domain.Company;
import eg.com.itiga.domain.RegCompany;
import eg.com.itiga.repository.company.CompanyDao;
import eg.com.itiga.repository.exception.DataException;
import eg.com.itiga.repositoryimpl.base.BaseDaoImpl;
import eg.com.itiga.repositoryimpl.base.HibernateUtil;

public class CompanyDaoImpl extends BaseDaoImpl implements CompanyDao {

	public final static String REQUESTED = "REQUESTED";

	public void delete(Company obj) throws DataException {
		// TODO Auto-generated method stub

	}

	public Company find(int id) throws DataException {
		// TODO Auto-generated method stub
		return null;
	}

	public List<Company> findAll() throws DataException {
		// TODO Auto-generated method stub
		return null;
	}

	public void saveOrUpdate(Company obj) throws DataException {
		// TODO Auto-generated method stub

	}

		public RegCompany retriveCompanyData(int id) throws DataException {
		// TODO Auto-generated method stub

		RegCompany c = new RegCompany();

		Session session = HibernateUtil.getCurrentSession();
		Criterion userIDeq = Restrictions.eq("user.userId", id);
		Criteria crt = session.createCriteria(RegCompany.class);
		crt.add(userIDeq);

		c = (RegCompany) crt.uniqueResult();

		return c;
	}

	public List<Company> getCompanyByStatus(boolean status)
			throws DataException {
		// TODO Auto-generated method stub
		List<Company> res = null;
		try {
			Session session = HibernateUtil.getCurrentSession();
			session.beginTransaction();
			Query q = session.createQuery("from Company where CIsRegistered="
					+ status);
			res = q.list();

		} catch (Exception ex) {
			ex.printStackTrace();
		}

		return res;
	}
	
	public void updateCompany(RegCompany obj) throws DataException {
		Session session= HibernateUtil.getCurrentSession();
		String companyQuere="update Company set CName = '"+obj.getCName()+"'where CId ="+obj.getCId();
		SQLQuery q1=session.createSQLQuery(companyQuere);
		System.out.println("The WebSite inside the Company dao updatting======= "+obj.getRegWesite());
		String quere="update RegCompany set CState = '"+obj.getCState()+"' regWesite ='"+obj.getRegWesite()+"'where cId ="+obj.getCId();
		SQLQuery q= session.createSQLQuery(quere);
		
		}

}
